package com.hadwinling.map.web;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gem.entity.Hotel;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @Auther: jzhang
 * @Date: 2019/10/23 09:10
 * @Description: 主页
 */
@Controller
@RequestMapping("/home")
public class IndexController {
    @RequestMapping("/index")
    public String index(Model model) {
        Hotel hotel = new Hotel();
        List<Hotel> hotelList = hotel.selectList(new QueryWrapper<>());
        List list = new ArrayList();
        for (Hotel ho: hotelList) {
            JSONObject object = new JSONObject();
            BigDecimal[] point = {ho.getLongitude(),ho.getLatitude()};
            object.put("position", point);
            object.put("name", ho.getName());
            object.put("img", ho.getImg());
            object.put("detailAddress", ho.getDetailAddress());
            list.add(object);
        }
        model.addAttribute("hotelList",list);
        model.addAttribute("urlFlag","index");
        return "index";
    }
}
